package com.io.example.demoparent.task;

import org.springframework.util.backoff.BackOff;
import org.springframework.util.backoff.BackOffExecution;
import org.springframework.util.backoff.FixedBackOff;

public class FixedBackOff_01 {

    long interval = 1000;   //重试间隔    1s重试一次
    long maxAttempts = 10;  //最大重试次数 最多重试10次
    BackOff backOff = new FixedBackOff(interval, maxAttempts);
    BackOffExecution execution = backOff.start( );


    private void withdrawAndKeep() {
        while (true) {
            long value = execution.nextBackOff( );
            if (value == BackOffExecution.STOP) {
                break;
            } else {
                //在这里写你的重试逻辑
            }
        }
    }
}
